/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package NicholasValueBeans;

import NicholasDatabase.SQLqueries;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author ChuckToh
 */
public class VotingList {

    private String voteTopics;
    private Date dateCreated, dateStart, dateEnd;

    public VotingList() {
    }

    public VotingList(String voteTopics, Date dateCreated, Date dateStart, Date dateEnd) {
        this.voteTopics = voteTopics;
        this.dateCreated = dateCreated;
        this.dateStart = dateStart;
        this.dateEnd = dateEnd;
    }

    public void setVoteTopics(String voteTopics) {
        this.voteTopics = voteTopics;
    }

    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    public void setDateStart(Date dateStart) {
        this.dateStart = dateStart;
    }

    public void setDateEnd(Date dateEnd) {
        this.dateEnd = dateEnd;
    }

    public boolean insertVotingList() {
        boolean success = false;

        try {
            SQLqueries sql = new SQLqueries();
            int insertResults = sql.insertVotingList(voteTopics, dateCreated, dateStart, dateEnd);

            if (insertResults != 0) {
                success = true;
            }

            sql.closeQuery();
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
        }

        return success;
    }

    public boolean ongoingVotingList() {
        boolean ongoingVotingList = false;

        try {
            SQLqueries sql = new SQLqueries();
            ResultSet votingListQuery = sql.votingListQuery(dateStart);

            if (votingListQuery.next()) {
                ongoingVotingList = true;
            }

            votingListQuery.close();
            sql.closeQuery();
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
            ongoingVotingList = true;
        }

        return ongoingVotingList;
    }

    public ResultSet getAllVotingLists() {
        SQLqueries sql = new SQLqueries();
        ResultSet allVotingListQuery = null;
        try {
            allVotingListQuery = sql.allVotingListQuery();
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
        }

        return allVotingListQuery;
    }
}
